<template>
    <f7-page :page-content="false" class="v-statistics" style="background-color: #f4f6f9">
        <f7-navbar>
            <f7-nav-left>
                <f7-link back icon-material="chevron_left" force></f7-link>
            </f7-nav-left>
            <f7-nav-title>移动机械统计</f7-nav-title>
            <f7-nav-right> </f7-nav-right>
        </f7-navbar>
        <div class="card-box" style="margin-top: 50px">
            <div class="info">
                <div class="s-title">
                    <span style="width: 65%">设备使用情况</span>
                </div>
                <div class="info-content">
                    <div @click="fnToList('useStatusList', 'enter')">
                        <img src="../../../../../assets/img/qzjx/mobile/icon_mobileequip.png" alt="" />
                        <div>
                            <div class="text">在场移动机</div>
                            <span>{{ enterRegisterNum || 0 }}</span>
                        </div>
                    </div>
                    <div @click="fnToListEng()">
                        <img src="../../../../../assets/img/qzjx/mobile/icon_engi_green.png" alt="" />
                        <div>
                            <div class="text">涉及工程</div>
                            <span>{{ engineeNum || 0 }}</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-content">
                <div class="title">
                    <img src="../../../../../assets/img/qzjx/mobile/icon_register.png" alt="" class="small-img" />
                    进退场登记统计
                </div>
                <ul class="box">
                    <li class="data-item" @click="fnToList('useStatusList', 'enter,exit')">
                        <div style="color: #3385ff">{{ registerNum || 0 }}</div>
                        <div>累计<span class="light">进场</span>设备</div>
                    </li>
                    <li class="data-item" @click="fnToList('useStatusList', 'exit')">
                        <div style="color: #8995ac">{{ exitRegisterNum || 0 }}</div>
                        <div>累计<span class="light">退场</span>设备</div>
                    </li>
                    <!-- <li class="data-item" @click="fnToListEng()">
                        <div style="color: #ff9f24">{{ notExistEngineeCount || 0 }}</div>
                        <div>未登记移动<br />设备的工程</div>
                    </li> -->
                </ul>
            </div>
            <div class="charts mt15">
                <div class="s-subTitle">
                    <div><span>各区在用移动机数量</span></div>
                    <!-- <van-icon name="arrow" /> -->
                </div>
                <f7-echarts :options="options" ref="echarts" class="echarts" @zrclick="handleClickChart"></f7-echarts>
            </div>
            <div class="process-box mt15">
                <div class="s-title">
                    <span><img src="../../../../../assets/img/qzjx/mobile/icon_type.png" alt="" />设备类型统计</span>
                    <!-- <van-icon name="arrow" /> -->
                </div>
                <div class="tab-content">
                    <template v-if="equipmentTypeList.length > 0">
                        <progress-item v-for="(item, index) in equipmentTypeList" :key="index"
                            @click.native="fnToList('equipmentType', item.equipmentType)" :total="equipmentTypeTotal"
                            :model="item" :sort="Number(index) + 1"
                            :mobileEquipmentType="mobileEquipmentType"></progress-item>
                    </template>
                    <template v-else>
                        <van-empty image-size="80" description="暂无数据" />
                    </template>
                </div>
            </div>
            <div class="relate-box mt15">
                <div class="s-subTitle">
                    <div><span>相关统计</span></div>
                </div>
                <ul class="relate-list">
                    <li class="relate-item maintain" @click="fnToList('type', 'maintenancenNotTimely')">
                        <img src="../../../../../assets/img/qzjx/mobile/icon_maintain.png" alt="" />
                        <span class="relate-num">{{ maintenancenNotTimelyNum }}<label>个</label></span>
                        <span class="relate-tips">未及时维保</span>
                    </li>
                    <li class="relate-item patrol" @click="fnToList('type', 'patrolNotTimely')">
                        <img src="../../../../../assets/img/qzjx/mobile/icon_patrol.png" alt="" />
                        <span class="relate-num">{{ patrolNotTimelyNum }}<label>个</label></span>
                        <span class="relate-tips">未及时巡检</span>
                    </li>
                    <li class="relate-item overtime" @click="fnToList('type', 'overdueNoDispose')">
                        <img src="../../../../../assets/img/qzjx/mobile/icon_rectification.png" alt="" />
                        <span class="relate-num">{{ overdueNoDisposeNum }}<label>个</label></span>
                        <span class="relate-tips">超时未整改</span>
                    </li>
                </ul>
            </div>
        </div>
    </f7-page>
</template>

<script>
import Controller from "@/libs/framework/controller";
import ProgressItem from "../components/ProgressItem.vue";
export default class instance extends Controller {
    onBeforeInit() {
        this.urls = {
            model: ["/equipment/eqmMobileRegister/getRegisterStatistics",
                "/equipment/eqmMobileRegister/queryEquipmentTypeList",
                "/equipment/eqmMobileRegister/getNotTimelyRegisterStatistics",
                '/equipment/eqmMobileRegister/getRegisterStatisticsByArea'],
        };
    }
    onAfterQuery(type, isSuccess, result) {
        if (type == 'form') {
            this.context.engineeNum = result.parameters?.engineeNum
            this.context.enterRegisterNum = result.parameters?.enterRegisterNum
            this.context.exitRegisterNum = result.parameters?.exitRegisterNum
            this.context.registerNum = result.parameters?.registerNum
        } else if (type == 'form$1') {
            this.context.equipmentTypeList = result.parameters?.data || [];
            this.context.mobileEquipmentType = result.parameters?.mobileEquipmentType || [];
            this.context.equipmentTypeTotal = 0;
            this.context.equipmentTypeTotal = result.parameters.data.reduce((prev, next) => {
                return prev + Number(next.num)
            }, 0)
        } else if (type == 'form$2') {
            this.context.maintenancenNotTimelyNum = result.parameters?.maintenancenNotTimelyNum
            this.context.overdueNoDisposeNum = result.parameters?.overdueNoDisposeNum
            this.context.patrolNotTimelyNum = result.parameters?.patrolNotTimelyNum
        } else if (type == 'form$3') {
            const data = result.parameters?.data;
            this.context.options.xAxis.data = data.map(item => item.areaName)
            const realData = data.map(item => item.num)
            const totalNum = realData.reduce((prev, curr) => prev + curr, 0)
            this.context.options.series[0].data = realData.map((item) => {
                return {
                    realValue: item,
                    value: totalNum
                }
            });
            this.context.options.series[1].data = realData;
            this.vm.$forceUpdate()
        }

        return result;
    }
    mixin() {
        return {
            components: {
                ProgressItem,
            },
            data() {
                return {
                    engineeNum: 0,
                    enterRegisterNum: 0,
                    exitRegisterNum: 0,
                    registerNum: 0,
                    equipmentTypeTotal: 0,
                    equipmentTypeList: [],
                    mobileEquipmentType: [],
                    maintenancenNotTimelyNum: 0,
                    overdueNoDisposeNum: 0,
                    patrolNotTimelyNum: 0,
                    options: {
                        tooltip: {
                            trigger: "item",
                        },
                        grid: {
                            top: "18%",
                            bottom: "10%",
                            left: "10",
                            right: "10",
                        },
                        xAxis: {
                            type: "category",
                            data: [],
                            axisLabel: {
                                show: true,
                                interval: 0,
                                textStyle: {
                                    color: "#5A6683", //文字的颜色
                                    fontSize: 10,
                                },
                            },
                            axisLine: {
                                show: false,
                            },
                            axisTick: {
                                show: false,
                            },
                        },
                        yAxis: {
                            type: "value",
                            show: false,
                        },
                        series: [
                            {
                                type: "bar",
                                data: [],
                                silent: true, // 图形不响应和触发鼠标事件
                                barWidth: 10,
                                barGap: "-100%",
                                itemStyle: {
                                    normal: {
                                        color: "#EBEEF5",
                                        barBorderRadius: 6,
                                        label: {
                                            show: true,
                                            position: "top",
                                            textStyle: {
                                                color: "#243357",
                                                fontWeight: "600",
                                                fontSize: 12,
                                            },
                                            formatter(params) {
                                                return params.data.realValue;
                                            },
                                        },
                                    },
                                },
                            },
                            {
                                type: "bar",
                                data: [],
                                barWidth: 10,
                                itemStyle: {
                                    normal: {
                                        color: "#3385FF",
                                        barBorderRadius: 6,
                                        label: {
                                            show: false,
                                        },
                                    },
                                },
                            },
                        ],
                    }
                };
            },
            methods: {
                handleClickChart(params) {
                    if(params.dataY.realValue > 0){
                        this.fnToList("areaName", params.dataX);
                    }
                },
                // 设备列表
                fnToList(key, value) {
                    let url = `/business/qzjx/mobileEquipment/statistic/equipList`;
                    if (key) {
                        let map = {};
                        map[key] = value
                        if (key == 'equipmentType' || key == 'areaName') {
                            map['useStatusList'] = 'enter'
                        }
                        url = this.$util.appendUrl(url, map);
                    }
                    this.$f7router.navigate(url);
                },
                // 工程列表
                fnToListEng() {
                    let url = `/business/qzjx/mobileEquipment/statistic/engineerList`;
                    this.$f7router.navigate(url);
                }
            },
        };
    }
}
</script>

<style lang="less" scoped>
@deep: ~">>>";

.v-statistics {
    padding: 10px 15px;
    overflow-y: auto;
}

.card-box {
    padding: 12px 16px;
    background: #ffffff;
    box-shadow: 0px 10px 20px 0px rgba(0, 0, 0, 0.05);
    border-radius: 8px;
    margin-bottom: 15px;

    >h4 {
        margin: 0;
        display: flex;
        justify-content: space-between;

        >span {
            font-size: 16px;
            font-weight: 500;
            color: #0f1826;
            line-height: 22px;
        }

        >div {
            width: 75px;
            display: flex;
            flex-direction: row-reverse;
        }
    }

    .info {
        width: 100%;

        .info-content {
            display: flex;
            justify-content: space-between;
            margin: 10px 0;

            >div {
                width: 48%;
                padding: 15px;
                background: #f3f9ff;
                box-sizing: border-box;
                border-radius: 4px;
                display: flex;
                align-items: center;

                &:nth-child(2) {
                    background: #eefbf9;
                }

                img {
                    width: 38px;
                    margin-right: 15px;
                }

                >div {
                    flex: 1;

                    span {
                        font-size: 18px;
                        font-weight: 600;
                        color: #0f1826;
                    }
                }
            }
        }
    }

    .process-box {
        background: linear-gradient(180deg, #ebf5ff 0%, #fafdff 100%);
        border-radius: 6px;
        padding: 15px 7px;

        .s-title {
            margin-bottom: 15px;
            padding: 0 5px;

            span {
                display: flex;
                align-items: center;
            }

            img {
                width: 15px;
                margin-right: 5px;
            }
        }

        .tab-content {
            background: #fff;
            border-radius: 6px;
            padding: 15px 0;
        }
    }

    .card-content {
        border-radius: 4px;
        margin-bottom: 10px;
        overflow: hidden;
        position: relative;
        border: 1px solid #d1e5fe;

        .title {
            color: #0f1826;
            font-size: 14px;
            display: flex;
            align-items: center;
            background: linear-gradient(229deg, #f3faff 100%, #eef7ff 100%);
            padding: 10px;
            border-bottom: 1px solid #d1e5fe;

            >i {
                width: 12px;
                height: 12px;
                flex-shrink: 0;
                margin-right: 6px;
                background-repeat: no-repeat;
                background-position: center;
                background-size: cover;
                background-image: url("../../../../../assets/img/qzjx/mobile/icon_msg.png");
            }

            img {
                width: 15px;
                height: 15px;
                flex-shrink: 0;
                margin-right: 6px;
            }
        }

        .box {
            width: 100%;
            box-sizing: border-box;
            padding: 16px 0;
            background: #fcfeff;
            display: flex;
            flex-wrap: wrap;
            justify-content: space-between;

            .data-item {
                width: 33%;
                margin-bottom: 6px;

                >div {
                    text-align: center;

                    &:nth-of-type(1) {
                        font-size: 18px;
                        font-weight: 600;
                    }

                    &:nth-of-type(2) {
                        color: #61677a;
                        font-size: 12px;
                        margin-top: 2px;
                    }
                }

                .light {
                    color: #333333;
                    font-weight: 600;
                }
            }
        }

        .list-box {
            background: #fafafc;
            min-height: 102px;

            .item {
                line-height: 22px;
                color: #61677a;
                font-size: 12px;
                display: flex;
                padding: 0 8px;
                margin-bottom: 4px;

                >div {
                    flex: 1;
                }
            }
        }

        .line {
            display: inline-block;
            position: absolute;
            width: 2px;
            height: 50%;
            background: #cccccc50;
            top: 37%;
            left: 35%;
        }
    }

    .echarts {
        height: 200px;
    }

    .text {
        color: #61677a;
    }

    .van-icon.van-icon-arrow {
        color: #ced6e0;
    }

    ::v-deep .v-progress {
        label {
            margin-bottom: 0;
        }
    }

    .relate-box {
        .relate-list {
            display: flex;
            margin-top: 14px;

            .relate-item {
                display: flex;
                flex-direction: column;
                align-items: center;
                justify-content: center;
                width: 97px;
                height: 114px;

                border-radius: 4px;

                +.relate-item {
                    margin-left: 10px;
                }

                img {
                    width: 26px;
                    height: 26px;
                    margin-bottom: 5px;
                }

                .relate-tips {
                    margin-top: 8px;
                    font-size: 14px;
                    color: #5F6981;
                }

                .relate-num {
                    font-weight: 600;
                    font-size: 18px;
                    color: #1F2C4C;

                    label {
                        font-size: 12px;
                    }
                }

                &.maintain {
                    background: linear-gradient(180deg,
                            #f3faff 0%,
                            rgba(243, 250, 255, 0) 100%);
                    border: 1px solid #e8eff8;
                }

                &.patrol {
                    background: linear-gradient(180deg, #F6F4FF 0%, rgba(246, 244, 255, 0.05) 100%);
                    border: 1px solid #F3F2F7;
                }

                &.overtime {
                    background: linear-gradient(180deg, #FFFBF4 0%, rgba(255, 251, 244, 0.05) 100%);
                    border: 1px solid #F7F5F2;
                }
            }
        }
    }
}

.s-title {
    color: #0f1826;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.s-subTitle {
    display: flex;
    align-items: center;
    justify-content: space-between;

    div {
        position: relative;
        font-size: 14px;
        color: #333333;
        font-weight: 600;

        span {
            position: relative;
            z-index: 1;
        }

        &:after {
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            height: 8px;
            width: 100%;
            background: linear-gradient(90deg, rgba(70, 165, 255, 0.4) 0%, #fff 100%);
        }
    }
}

.mt15 {
    margin-top: 20px;
}

.echarts {
    width: 106% !important;
    margin-left: -3%;
}
</style>
